//
//  DTLPasswordTextFieldView.m
//  DTLLiteProject
//
//  Created by Kendama on 2017/7/20.
//  Copyright © 2017年 JianWei Chen. All rights reserved.
//

#import "PasswordTextFieldView.h"

@implementation PasswordTextFieldView

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        [self masLayoutSubviews];
        
    }
    return self;
}

- (void)hidePassword
{
    self.passwordTextField.secureTextEntry = self.hideButton.selected;
    self.hideButton.selected = !self.hideButton.selected;
}

- (UITextField *)passwordTextField
{
    if(!_passwordTextField)
    {
        UIView *superView = self;
        _passwordTextField = [[UITextField alloc]init];
        _passwordTextField.font = [UIFont systemFontOfSize:15];
        _passwordTextField.secureTextEntry = YES;
        [superView addSubview:_passwordTextField];
        _passwordTextField.textColor = [UIColor whiteColor];
    }
    return _passwordTextField;
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
    }
    return _iconImageView;
}

- (UIButton *)hideButton
{
    if(!_hideButton)
    {
        UIView *superView = self;
        _hideButton = [[UIButton alloc]init];
        [superView addSubview:_hideButton];
        [_hideButton setImage:[UIImage imageNamed:@"icon_invisible_nor"] forState:UIControlStateNormal];
        [_hideButton setImage:[UIImage imageNamed:@"icon_visible_sel"] forState:UIControlStateSelected];
        [_hideButton addTarget:self action:@selector(hidePassword) forControlEvents:UIControlEventTouchUpInside];
        [_hideButton sizeToFit];
    }
    return _hideButton;
}


- (void)masLayoutSubviews{
    __weak UIView *superView = self;
    UIView *line = [[UIView alloc] init];
    [superView addSubview:line];
    line.backgroundColor = rgba(48,70,118,1);
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(superView);
        make.height.mas_equalTo(1);
        make.bottom.mas_equalTo(superView.mas_bottom);
    }];
    
//    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.mas_equalTo(superView.mas_centerY);
//        make.left.mas_equalTo(line.mas_left);
//        make.width.height.mas_equalTo(px1080Width(80));
//    }];
    
    [self.passwordTextField mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(self.iconImageView.mas_right).with.offset(px1080Width(35));
        make.left.mas_equalTo(line.mas_left);
        make.centerY.equalTo(superView);
        make.height.mas_equalTo(px1920Height(70));
        make.right.mas_equalTo(self.hideButton.mas_left);
    }];
    
    [self.hideButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.right.mas_equalTo(line.mas_right);
        make.width.mas_equalTo(px1080Width(80));
    }];
}

@end
